//
//  JCPlanHeadView.m
//  JiFengDaRen
//
//  Created by 陈如意 on 2018/5/10.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCPlanHeadView.h"

@interface JCPlanHeadView()

@property (nonatomic, strong) UILabel * titleName;
@property (nonatomic, strong) UILabel * contentName;


@end

@implementation JCPlanHeadView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self initUI];
    }
    
    return self;
}


- (void)initUI{
    
    self.titleName = [UILabel new];
    self.titleName.textColor = [UIColor colorWithHexString:@"#0E8AEE"];
    self.titleName.font = KSHSystemFont(14);
    [self addSubview:self.titleName];
    
    self.contentName = [UILabel new];
    self.contentName.textColor = [UIColor colorWithHexString:@"#0E8AEE"];
    self.contentName.font = KSHSystemFont(14);
    [self addSubview:self.contentName];
    
    self.addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.addBtn.titleLabel.font = KSHSystemFont(14);
    [self.addBtn setTitleColor:[UIColor colorWithHexString:@"#0E8AEE"] forState:UIControlStateNormal];
    self.addBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.addBtn addTarget:self action:@selector(addBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.addBtn];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(__I6Width(20));
        make.centerY.equalTo(self);
    }];
    
//    [self.contentName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self).offset(-__I6Width(20));
//        make.centerY.equalTo(self);
//    }];
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-__I6Width(20));
//        make.centerY.equalTo(self);
        make.top.bottom.equalTo(self);
        make.width.mas_offset(200);
    }];
}

- (void)addBtnAction:(UIButton *)btn{
    if ([_delegate respondsToSelector:@selector(clickAddBtnAction:)]) {
        [_delegate clickAddBtnAction:btn];
    }
}

- (void)getHeadTitle:(NSMutableDictionary *)dic andIndex:(NSInteger)index{
    self.titleName.text = dic[@"titleName"][index];
    [self.addBtn setTitle:dic[@"contentName"][index] forState:UIControlStateNormal];
    if (index == 1) {
        [self.addBtn setImage:[UIImage imageNamed:@"setting_plan_icon_add"] forState:UIControlStateNormal];
    }else{
        [self.addBtn setImage:nil forState:UIControlStateNormal];
    }
}

@end
